package cn.dwong.msgGateway.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * @author 73202
 * @date 2022/3/10 14:23
 */
@Component
public class RedisOperator {
    @Autowired
    private StringRedisTemplate redisTemplate;

    /**
     * 实现命令：set key value ex seconds,超时时间为秒
     * @param key
     * @param value
     * @param timeout
     */
    public boolean setNx(String key,String value,long timeout){
        return redisTemplate.opsForValue().setIfAbsent(key,value,timeout, TimeUnit.MILLISECONDS);

    }
}
